Skip to contentSkip to conversation

Change in openvpn[master]: dns: Fix bug in error handling when talking to script

Openvpn-devel In review flichtenheld (Code Review) 2 participants 6 messages Sep 23, 2025 – Sep 24, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1758637530000.Ic395b6d1dce510bb4b499c5beba61f033a2a860b@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email

to review the following change.

Change subject: dns: Fix bug in error handling when talking to script
......................................................................

dns: Fix bug in error handling when talking to script

Comparing the result of read/write to a size_t value is dangerous C. Since ssize_t and size_t have the same size ssize_t is promoted to size_t, so -1 becomes size_t max value and is not smaller than the expected length.

Make sure to compare ssize_t to ssize_t to avoid any suprises.

Change-Id Ic395b6d1dce510bb4b499c5beba61f033a2a860b

---
M src/openvpn/dns.c

1 file changed, 5 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1208/1

src/openvpn/dns.c +5 -6
index efb888a..2a9e60b 100644
@@ -642,11 +642,10 @@
 
         while (1)
         {
-            ssize_t rlen, wlen;
             char path[PATH_MAX];
 
             /* Block here until parent sends a path */
-            rlen = read(dns_pipe_fd[0], &path, sizeof(path));
+            ssize_t rlen = read(dns_pipe_fd[0], &path, sizeof(path));
             if (rlen < 1)
             {
                 if (rlen == -1 && errno == EINTR)
@@ -665,8 +664,8 @@
             /* Unblock parent process */
             while (1)
             {
-                wlen = write(ack_pipe_fd[1], &res, sizeof(res));
-                if ((wlen == -1 && errno != EINTR) || wlen < sizeof(res))
+                ssize_t wlen = write(ack_pipe_fd[1], &res, sizeof(res));
+                if ((wlen == -1 && errno != EINTR) || wlen < (ssize_t)sizeof(res))
                 {
                     /* Not much we can do about errors but exit */
                     close(dns_pipe_fd[0]);
@@ -727,7 +726,7 @@
         env_set_write_file(dvf, es);
 
         int wfd = updown_runner->fds[1];
-        size_t dvf_size = strlen(dvf) + 1;
+        ssize_t dvf_size = strlen(dvf) + 1;
         while (1)
         {
             ssize_t len = write(wfd, dvf, dvf_size);
@@ -746,7 +745,7 @@
         while (1)
         {
             ssize_t len = read(rfd, &status, sizeof(status));
-            if (len < sizeof(status))
+            if (len < (ssize_t)sizeof(status))
             {
                 if (len == -1 && errno == EINTR)
                 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic395b6d1dce510bb4b499c5beba61f033a2a860b
Gerrit-Change-Number: 1208
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

d12fk has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email )

Change subject: dns: Fix bug in error handling when talking to script
......................................................................

Patch Set 1: Code-Review+2

(1 comment)

Patchset:

PS1:
LGTM

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic395b6d1dce510bb4b499c5beba61f033a2a860b
Gerrit-Change-Number: 1208
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 24 Sep 2025 12:17:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw

PATCH 1/1 dns: Fix bug in error handling when talking to script

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

Comparing the result of read/write to a size_t value is dangerous C. Since ssize_t and size_t have the same size ssize_t is promoted to size_t, so -1 becomes size_t max value and is not smaller than the expected length.

Make sure to compare ssize_t to ssize_t to avoid any suprises.

Change-Id Ic395b6d1dce510bb4b499c5beba61f033a2a860b

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1208
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1208
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Heiko Hund <[email protected]...>

src/openvpn/dns.c +5 -6
index efb888a..2a9e60b 100644
@@ -642,11 +642,10 @@
 
         while (1)
         {
-            ssize_t rlen, wlen;
             char path[PATH_MAX];
 
             /* Block here until parent sends a path */
-            rlen = read(dns_pipe_fd[0], &path, sizeof(path));
+            ssize_t rlen = read(dns_pipe_fd[0], &path, sizeof(path));
             if (rlen < 1)
             {
                 if (rlen == -1 && errno == EINTR)
@@ -665,8 +664,8 @@
             /* Unblock parent process */
             while (1)
             {
-                wlen = write(ack_pipe_fd[1], &res, sizeof(res));
-                if ((wlen == -1 && errno != EINTR) || wlen < sizeof(res))
+                ssize_t wlen = write(ack_pipe_fd[1], &res, sizeof(res));
+                if ((wlen == -1 && errno != EINTR) || wlen < (ssize_t)sizeof(res))
                 {
                     /* Not much we can do about errors but exit */
                     close(dns_pipe_fd[0]);
@@ -727,7 +726,7 @@
         env_set_write_file(dvf, es);
 
         int wfd = updown_runner->fds[1];
-        size_t dvf_size = strlen(dvf) + 1;
+        ssize_t dvf_size = strlen(dvf) + 1;
         while (1)
         {
             ssize_t len = write(wfd, dvf, dvf_size);
@@ -746,7 +745,7 @@
         while (1)
         {
             ssize_t len = read(rfd, &status, sizeof(status));
-            if (len < sizeof(status))
+            if (len < (ssize_t)sizeof(status))
             {
                 if (len == -1 && errno == EINTR)
                 {
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: dns: Fix bug in error handling when talking to script

So all this integer warning work has actually *found* something - in the error case, this would spin and loop, and not properly abort the attempt. C is... weird at times.

Your patch has been applied to the master branch.

commit bd27319f2afae4c990502a434df425ff23e1e031

Author: Frank Lichtenheld
Date:   Wed Sep 24 14:18:55 2025 +0200
     dns: Fix bug in error handling when talking to script

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Heiko Hund <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1208
     Message-Id: <[email protected]...>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59238099/
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by d12fk

Change subject: dns: Fix bug in error handling when talking to script
......................................................................

dns: Fix bug in error handling when talking to script

Comparing the result of read/write to a size_t value is dangerous C. Since ssize_t and size_t have the same size ssize_t is promoted to size_t, so -1 becomes size_t max value and is not smaller than the expected length.

Make sure to compare ssize_t to ssize_t to avoid any suprises.

Change-Id Ic395b6d1dce510bb4b499c5beba61f033a2a860b

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1208
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59238099/

---
M src/openvpn/dns.c

1 file changed, 5 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1208/2

src/openvpn/dns.c +5 -6
index efb888a..2a9e60b 100644
@@ -642,11 +642,10 @@
 
         while (1)
         {
-            ssize_t rlen, wlen;
             char path[PATH_MAX];
 
             /* Block here until parent sends a path */
-            rlen = read(dns_pipe_fd[0], &path, sizeof(path));
+            ssize_t rlen = read(dns_pipe_fd[0], &path, sizeof(path));
             if (rlen < 1)
             {
                 if (rlen == -1 && errno == EINTR)
@@ -665,8 +664,8 @@
             /* Unblock parent process */
             while (1)
             {
-                wlen = write(ack_pipe_fd[1], &res, sizeof(res));
-                if ((wlen == -1 && errno != EINTR) || wlen < sizeof(res))
+                ssize_t wlen = write(ack_pipe_fd[1], &res, sizeof(res));
+                if ((wlen == -1 && errno != EINTR) || wlen < (ssize_t)sizeof(res))
                 {
                     /* Not much we can do about errors but exit */
                     close(dns_pipe_fd[0]);
@@ -727,7 +726,7 @@
         env_set_write_file(dvf, es);
 
         int wfd = updown_runner->fds[1];
-        size_t dvf_size = strlen(dvf) + 1;
+        ssize_t dvf_size = strlen(dvf) + 1;
         while (1)
         {
             ssize_t len = write(wfd, dvf, dvf_size);
@@ -746,7 +745,7 @@
         while (1)
         {
             ssize_t len = read(rfd, &status, sizeof(status));
-            if (len < sizeof(status))
+            if (len < (ssize_t)sizeof(status))
             {
                 if (len == -1 && errno == EINTR)
                 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic395b6d1dce510bb4b499c5beba61f033a2a860b
Gerrit-Change-Number: 1208
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email )

Change subject: dns: Fix bug in error handling when talking to script
......................................................................

dns: Fix bug in error handling when talking to script

Comparing the result of read/write to a size_t value is dangerous C. Since ssize_t and size_t have the same size ssize_t is promoted to size_t, so -1 becomes size_t max value and is not smaller than the expected length.

Make sure to compare ssize_t to ssize_t to avoid any suprises.

Change-Id Ic395b6d1dce510bb4b499c5beba61f033a2a860b

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1208
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59238099/

---
M src/openvpn/dns.c

1 file changed, 5 insertions(+), 6 deletions(-)
src/openvpn/dns.c +5 -6
index efb888a..2a9e60b 100644
@@ -642,11 +642,10 @@
 
         while (1)
         {
-            ssize_t rlen, wlen;
             char path[PATH_MAX];
 
             /* Block here until parent sends a path */
-            rlen = read(dns_pipe_fd[0], &path, sizeof(path));
+            ssize_t rlen = read(dns_pipe_fd[0], &path, sizeof(path));
             if (rlen < 1)
             {
                 if (rlen == -1 && errno == EINTR)
@@ -665,8 +664,8 @@
             /* Unblock parent process */
             while (1)
             {
-                wlen = write(ack_pipe_fd[1], &res, sizeof(res));
-                if ((wlen == -1 && errno != EINTR) || wlen < sizeof(res))
+                ssize_t wlen = write(ack_pipe_fd[1], &res, sizeof(res));
+                if ((wlen == -1 && errno != EINTR) || wlen < (ssize_t)sizeof(res))
                 {
                     /* Not much we can do about errors but exit */
                     close(dns_pipe_fd[0]);
@@ -727,7 +726,7 @@
         env_set_write_file(dvf, es);
 
         int wfd = updown_runner->fds[1];
-        size_t dvf_size = strlen(dvf) + 1;
+        ssize_t dvf_size = strlen(dvf) + 1;
         while (1)
         {
             ssize_t len = write(wfd, dvf, dvf_size);
@@ -746,7 +745,7 @@
         while (1)
         {
             ssize_t len = read(rfd, &status, sizeof(status));
-            if (len < sizeof(status))
+            if (len < (ssize_t)sizeof(status))
             {
                 if (len == -1 && errno == EINTR)
                 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1208?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic395b6d1dce510bb4b499c5beba61f033a2a860b
Gerrit-Change-Number: 1208
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged